﻿namespace Xms.Abp.Components;

public class NumberColumn<TNumber> : Column<TNumber>
    where TNumber : struct, IFormattable
{
    public NumberColumn()
    {
        if (typeof(TNumber) == typeof(decimal))
        {
            Format = "N4";
        }
        else if (typeof(TNumber) == typeof(float) || typeof(TNumber) == typeof(double))
        {
            Format = "N6";
        }
        Style = "text-align:right;";
        Width = "120";
        HeaderStyle = "text-align:right;";

        ChildContent = builder =>
        {
            if (!Format.IsNullOrWhiteSpace())
            {
                builder.AddContent(0, Field.ToString(Format, null));
            }
            else
            {
                builder.AddContent(0, Field.ToString());
            }
        };
    }
}
